package com.instpower.things.helper;

/**
 * @ClassName BitUtil
 * @Author: hellmash@gmail.com
 * @Date: 2020/2/22
 * @Version: 1.0.0
 * @Description: 字节工具类
 */
public final class BitUtil {

    private BitUtil() {
    }

    public static boolean check(long number, int index) {
        return (number & (1 << index)) != 0;
    }

    public static int between(int number, int from, int to) {
        return (number >> from) & ((1 << to - from) - 1);
    }

    public static int from(int number, int from) {
        return number >> from;
    }

    public static int to(int number, int to) {
        return between(number, 0, to);
    }

    public static long between(long number, int from, int to) {
        return (number >> from) & ((1L << to - from) - 1L);
    }

    public static long from(long number, int from) {
        return number >> from;
    }

    public static long to(long number, int to) {
        return between(number, 0, to);
    }

    public static String formatStrng(int value){
        String v = Integer.toBinaryString(value);
        if(v.length() > 7)
            return String.format("%s", v.substring(v.length() - 8));

        return String.format("%s", v);
    }

}
